package  
{
	import com.bit101.components.Label;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author René Verheij
	 */
	public class Pawn extends Sprite
	{
		private var _color:Object;
		private var _id:Number;
		public var found:Number = 0;
		public var foundInARow:Number = 0;
		public var missed:Number = 0;
		public var missedInARow:Number = 0;
		private var lastMappingSucces:Boolean = false;
		private var lab:Label;
		
		public function Pawn(color:Object) 
		{
			_color = color;
			
			graphics.beginFill(color.color);
			graphics.drawCircle(0, 0, 10);
			
			
			this.buttonMode = true;
			
			addEventListener(MouseEvent.MOUSE_DOWN, _startDrag);
			addEventListener(MouseEvent.MOUSE_UP, _stopDrag);
			//addEventListener(MouseEvent.MOUSE_OUT, _stopDrag);
			//addEventListener(Event.ADDED_TO_STAGE, startPulse);
			//addEventListener("pulse", addPulse);
		}
		
		public function get id():Number
		{
			return _id;
		}
		public function set id(val:Number):void
		{
			_id = val;
			lab = new Label(this, -5, -5, _id.toString());
		}
		
		public function get color():Object
		{
			return _color;
		}
		
		public function foundMapping():void
		{
			found++;
			foundInARow++;
			missedInARow = 0;
		}
		public function missedMapping():void
		{
			missed++;
			missedInARow++;
			foundInARow = 0;
		}
		
		public function pulse(e:TimerEvent=null):void 
		{
			var pulse:Pulse = new Pulse(_color,this);
			pulse.x = this.x;
			pulse.y = this.y;
			Main.instance.addChild(pulse);
			Main.instance.setChildIndex(pulse, 0);
		}
		
		private function _stopDrag(e:MouseEvent):void 
		{
			stopDrag();
		}
		
		private function _startDrag(e:MouseEvent):void 
		{
			startDrag();
		}
		
		override public function toString():String 
		{
			return 'p'+id+' [f:' + found + ',' + foundInARow + ' m:' + missed + ',' + missedInARow+']';
		}
		
	}

}